package beautiful.butterfly.drds.binlog.packet;


import beautiful.butterfly.drds.binlog.utils.ByteUtils;
import io.netty.buffer.ByteBuf;

import java.util.LinkedList;
import java.util.List;

public class RowPacket
{

    private String[] values;

    public RowPacket(ByteBuf byteBuf)
    {
        // LoggerUtils.debug(logger, "generate RowPacket");
        List<String> valueList = new LinkedList<String>();
        // 读取
        while (byteBuf.isReadable())
        {// 还有数据可读
            Number number = ByteUtils.readVariableNumber(byteBuf);
            int length = number.intValue();
            // 获取了长度，读取指定的字节
            String value = ByteUtils.readSpecifiedLengthString(byteBuf, length);
            valueList.add(value);
        }
        values = valueList.toArray(new String[valueList.size()]);
        // LoggerUtils.debug(logger, values.toString());
    }

    public String getValues(int index)
    {
        if (index >= 0 && index < values.length)
        {
            return values[index];
        }
        return null;

    }
}
